package labuladong.开篇;

import jdk.internal.dynalink.linker.LinkerServices;
import leetcode.ListNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class 数字排列 {
    static List<List<Integer>> result = new ArrayList<>();

    public static void backtrack(int[] nums, List<Integer> list) {
        if (list.size() == nums.length) {
            result.add(new LinkedList<>(list));
            return;
        }

        for (int i=0; i<nums.length; i++) {
            if (list.contains(nums[i])) {
                continue;
            }

            list.add(nums[i]);
            backtrack(nums, list);
            list.remove(list.size()-1);
        }
    }

    public static void main(String[] args) {
        backtrack(new int[]{1, 2, 3}, new ArrayList<>());
        for (List list : result) {
            for (int i=0; i<list.size(); i++) {
                System.out.print(list.get(i) + " ");
            }
            System.out.println();
        }
    }
}
